package actor.sensori;

import sde.actor.Message;
import sde.actor.Timer;
import attori.controller.ControllerTemperaturaIF;
import attori.model.Stanza;

public class SensoreTemperatura extends Sensore {
	Stanza stanza;

	private static class Timeout extends Message {
	}

	private ControllerTemperaturaIF controller;
	private Timer timer = new Timer();
	private Timeout timeout = new Timeout();
	private long periodo;

	public SensoreTemperatura(Stanza stanza,
			ControllerTemperaturaIF controller, long periodo) {
		super();
		this.stanza = stanza;
		this.controller = controller;
		this.periodo = periodo;
	}

	@Override
	public void sample() {
		controller.send(new ControllerTemperaturaIF.Temperatura(stanza
				.getTemperatura()));
	}

	@Override
	protected void handler(Message m) {
		if (m == timeout) {
			sample();
			timer.set(m, this, periodo);
		}

	}

}
